﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EvertonApp.Transporte;
using RestSharp;

namespace EvertonApp.AdminWeb.Controllers.Proxy
{
    public class OfertaProxy : IProxy<Oferta>
    {
        #region Implementation of IProxy<Oferta>

        public IEnumerable<Oferta> Get()
        {
            var request = new RestRequest();
            request.AddHeader("Content-Type", "application/json");
            request.RequestFormat = DataFormat.Json;
            request.Resource = "/api/oferta";
            request.RootElement = "Oferta";


            var response = ProxyHelper.ExecuteList<Oferta>(request);

            return response;
        }

        public Oferta Get(Guid id)
        {
            var request = new RestRequest();
            request.AddHeader("Content-Type", "application/json");
            request.RequestFormat = DataFormat.Json;

            request.AddParameter("id", id);
            request.Resource = "/api/oferta";
            request.RootElement = "Oferta";


            var response = ProxyHelper.Execute<Oferta>(request);

            return response;
        }

        public Oferta Post(Oferta value)
        {
            bool resultado = false;

            var request = new RestRequest();
            request.AddHeader("Content-Type", "application/json");
            request.RequestFormat = DataFormat.Json;

            request.Resource = "/api/oferta";
            request.AddObject(value);
            request.Method = Method.POST;

            var response = ProxyHelper.Execute<Oferta>(request);

            return response;
        }

        public bool Put(Guid id, Oferta value)
        {

            bool respuesta;

            var request = new RestRequest();
            request.AddHeader("Content-Type", "application/json");
            request.RequestFormat = DataFormat.Json;

            request.AddParameter("id", id);
            request.Resource = "/api/oferta";
            request.AddObject(value);
            request.Method = Method.PUT;

            var response = ProxyHelper.Execute(request);

            Boolean.TryParse(response.Content, out respuesta);

            return respuesta;
        }

        public bool Delete(Guid id)
        {
            bool respuesta;

            var request = new RestRequest();
            request.AddHeader("Content-Type", "application/json");
            request.RequestFormat = DataFormat.Json;

            request.AddParameter("id", id);
            request.Resource = "/api/oferta";
            request.Method = Method.DELETE;

            var response = ProxyHelper.Execute<Boolean>(request);

            return response;
        }

        #endregion
    }
}